using System;

namespace JamesKovacs.Examples.ContractManager {
	/// <summary>
	/// Strategy for recognizing revenue as follows: 1/3 immediately, 1/3 after first offset, and 1/3 after second offset.
	/// </summary>
	public class ThreeWayRecognitionStrategy: RecognitionStrategy  {
		#region Constructors
		/// <summary>
		/// Creates a new <see cref="ThreeWayRecognitionStrategy"/> instance.
		/// </summary>
		/// <param name="firstRecognitionOffset">First recognition offset.</param>
		/// <param name="secondRecognitionOffset">Second recognition offset.</param>
		public ThreeWayRecognitionStrategy(int firstRecognitionOffset, int secondRecognitionOffset) {
			m_firstRecognitionOffset = firstRecognitionOffset;
			m_secondRecognitionOffset = secondRecognitionOffset;
		}
		#endregion

		#region Overrides
		/// <summary>
		/// Calculates the revenue recognitions for a contract.
		/// </summary>
		/// <param name="contract">Contract on which to recognize revenues.</param>
		public override void CalculateRevenueRecognitions(Contract contract) {
			Money[] allocation = contract.Revenue.Allocate(3);
			contract.AddRevenueRecognition(new RevenueRecognition(allocation[0], contract.SigningDate));
			contract.AddRevenueRecognition(new RevenueRecognition(allocation[1], contract.SigningDate.AddDays(m_firstRecognitionOffset)));
			contract.AddRevenueRecognition(new RevenueRecognition(allocation[2], contract.SigningDate.AddDays(m_secondRecognitionOffset)));
		}
		#endregion

		#region Private fields
		private int m_firstRecognitionOffset;
		private int m_secondRecognitionOffset;
		#endregion
	}
}
